//
//  YMStatusToolsBarView.swift
//  YMWeiBo
//
//  Created by mimi on 16/7/24.
//  Copyright © 2016年 mimi. All rights reserved.
//

import UIKit

class YMStatusToolsBarView: UIView {
    
    var retweetButton:UIButton?
    var commentButton:UIButton?
    var unlikeButton:UIButton?
    
    
    var statusViewModel:YMStatusViewModel?{
        didSet{
            retweetButton?.setTitle(statusViewModel?.repostsCount, forState: .Normal)
            commentButton?.setTitle(statusViewModel?.commentsCount, forState: .Normal)
            unlikeButton?.setTitle(statusViewModel?.attitudesCount, forState: .Normal)
        }
    }
    
    

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func setupUI() {
        //添加
       retweetButton = addChildButton("timeline_icon_retweet", title: "转发")
       commentButton = addChildButton("timeline_icon_comment", title: "评论")
       unlikeButton = addChildButton("timeline_icon_unlike", title: "赞")
      
        
        //约束
        retweetButton!.snp_makeConstraints { (make) in
            make.top.bottom.leading.equalTo(self)
            make.width.equalTo(commentButton!)
            
        }
        
        commentButton!.snp_makeConstraints { (make) in
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweetButton!.snp_trailing)
            make.width.equalTo(unlikeButton!)
            
        }
        
        unlikeButton!.snp_makeConstraints { (make) in
            make.top.bottom.trailing.equalTo(self)
            make.leading.equalTo(commentButton!.snp_trailing)
            
        }
    }
    
    
        
    //        MARK: - 加载控件-bt的公共但方法
    
    func addChildButton(imageName:String,title:String) ->UIButton{
       
        let button = UIButton()
        button.setTitle(title, forState: .Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState:.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        button.setBackgroundImage(UIImage( named: "timeline_card_bottom_background"), forState: .Normal)
        button.setBackgroundImage(UIImage( named: "timeline_card_bottom_background_highlighted"), forState: .Highlighted)
        button.setImage(UIImage( named: imageName), forState: .Normal)
        addSubview(button)
        return button
    }
    
    
}
